package com.ruoyi.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.system.bo.ZsyyCommunityOpenDoorAddBo;
import com.ruoyi.system.bo.ZsyyCommunityOpenDoorQueryBo;
import com.ruoyi.system.bo.ZsyyCommunityOpenDoorEditBo;
import com.ruoyi.system.domain.ZsyyCommunityOpenDoor;
import com.ruoyi.system.mapper.ZsyyCommunityOpenDoorMapper;
import com.ruoyi.system.vo.ZsyyCommunityOpenDoorVo;
import com.ruoyi.system.service.IZsyyCommunityOpenDoorService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 开门记录Service业务层处理
 *
 * @author wangghua
 * @date 2021-07-14
 */
@Service
public class ZsyyCommunityOpenDoorServiceImpl extends ServicePlusImpl<ZsyyCommunityOpenDoorMapper, ZsyyCommunityOpenDoor> implements IZsyyCommunityOpenDoorService {
    @Autowired
    private ZsyyCommunityOpenDoorMapper iZsyyCommunityOpenDoorMapper;
	@Autowired
	private GetCommunityIdImpl getCommunityIdImpl;

    @Override
    public ZsyyCommunityOpenDoorVo queryById(Long id7){
        return getVoById(id7, ZsyyCommunityOpenDoorVo.class);
    }

    @Override
    public TableDataInfo<ZsyyCommunityOpenDoorVo> queryPageList(ZsyyCommunityOpenDoorQueryBo bo) {
		bo.setCommunityId(getCommunityIdImpl.getLoginUser().getCommunityId());
		Page<ZsyyCommunityOpenDoorVo> page = iZsyyCommunityOpenDoorMapper.queryPageList(PageUtils.buildPage(),bo);
		return PageUtils.buildDataInfo(page);
    }

    @Override
    public List<ZsyyCommunityOpenDoorVo> queryList(ZsyyCommunityOpenDoorQueryBo bo) {
		bo.setCommunityId(getCommunityIdImpl.getLoginUser().getCommunityId());
        return iZsyyCommunityOpenDoorMapper.queryList(bo);
    }

    private LambdaQueryWrapper<ZsyyCommunityOpenDoor> buildQueryWrapper(ZsyyCommunityOpenDoorQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ZsyyCommunityOpenDoor> lqw = Wrappers.lambdaQuery();
        return lqw;
    }

    @Override
    public Boolean insertByAddBo(ZsyyCommunityOpenDoorAddBo bo) {
        ZsyyCommunityOpenDoor add = BeanUtil.toBean(bo, ZsyyCommunityOpenDoor.class);
        validEntityBeforeSave(add);
        return save(add);
    }

    @Override
    public Boolean updateByEditBo(ZsyyCommunityOpenDoorEditBo bo) {
        ZsyyCommunityOpenDoor update = BeanUtil.toBean(bo, ZsyyCommunityOpenDoor.class);
        validEntityBeforeSave(update);
        return updateById(update);
    }

    /**
     * 保存前的数据校验
     *
     * @param entity 实体类数据
     */
    private void validEntityBeforeSave(ZsyyCommunityOpenDoor entity){
        //TODO 做一些数据校验,如唯一约束
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return removeByIds(ids);
    }
}
